package com.example.music.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class MergeMp3 {


    private static Logger logger = LoggerFactory.getLogger(MergeMp3.class);

    private static String path= PropertiesUtils.getProperties();



    /**
     *
     * @param songAccompany 歌曲伴奏
     * @param record 歌曲用户录音
     * @return
     */

    public static String mergeMp3(String songAccompany,String record) {
        songAccompany=path+songAccompany;
        record=path+record;
        String selfSingingOrigin=System.currentTimeMillis()+".mp3";
       String selfSinging=path+selfSingingOrigin;
        String fmPath="D:\\work\\项目\\浙师大心音行项目\\ffmpeg-20200802-b48397e-win64-shared\\ffmpeg-20200802-b48397e-win64-shared\\bin\\ffmpeg -i ";
        try {
            String cmd=fmPath+songAccompany+" -i " +record+" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f mp3 F:\\image\\music\\test.mp3";
            logger.info("cmd"+cmd);
            Runtime.getRuntime().exec(cmd);
            Thread.sleep(3000);
            logger.info("歌曲合成成功{}"+selfSinging);
            return selfSingingOrigin;
        }catch (InterruptedException e) {
            e.printStackTrace();
            return null;
        }
        catch (IOException e) {
            logger.info("歌曲合成失败{}"+selfSinging);
            e.printStackTrace();
            return null;
        }
    }

}
